<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="ss" uri="/WEB-INF/stripes-security.tld" %>
<s:layout-render name="/layout.jsp" title="${regions}">
    <s:layout-component name="menu"></s:layout-component>
    <s:layout-component name="main_content">
        <s:useActionBean var="regionAB" beanclass="cz.muni.fi.pa165.creatures.web.RegionsActionBean"/>
        <div class="main-content">
            <div class="content">
                 <ss:secure roles="admin">
                <img src="${pageContext.request.contextPath}/images/banner-admin.png" alt="Banner" id="banner"/>                
                </ss:secure>
                <ss:secure roles="user">
                <img src="${pageContext.request.contextPath}/images/banner-scout.png" alt="Banner" id="banner"/>                
                </ss:secure>
                <h1><f:message key="regions"/></h1>
                <ul class="navcontainer" id="main-navigation">
                    <li class="current"><s:link href="/regions/all"><f:message key="all"/></s:link></li>
                    <ss:secure roles="admin">
                        <li><s:link href="/regions/create"><f:message key="create"/></s:link></li>
                        <c:if test="${regionAB.count > 0}">
                            <li><s:link href="/regions/deleteall"><f:message key="remove_all"/></s:link></li>
                        </c:if>
                    </ss:secure>
                </ul>
                <s:form beanclass="cz.muni.fi.pa165.creatures.web.RegionsActionBean">
                    <table>
                        <thead>
                            <tr>
                                <th><f:message key="regionDTO.name"/></th>
                                <th><f:message key="regionDTO.description"/></th>
                                <th><f:message key="regionDTO.area"/></th>
                                <th><f:message key="region.creaturesCount"/></th>
                                <th colspan="4"><f:message key="actions"/></th>
                            </tr>
                        </thead>
                        <tbody>
                            <c:choose>
                                <c:when test="${regionAB.count > 0}">
                                    <c:forEach items="${regionAB.all}" var="regionDTO">
                                        <tr>
                                            <td><c:out value="${regionDTO.name}"/></td>
                                            <td><c:out value="${regionDTO.description}"/></td>
                                            <td><c:out value="${regionDTO.area}"/></td>
                                            <td><c:out value="${regionDTO.creaturesCount}"/></td>
                                            
                                            <ss:secure roles="admin">
                                                <td>
                                                    <s:link beanclass="cz.muni.fi.pa165.creatures.web.RegionsActionBean" event="remove">
                                                    <s:param name="regionDTO.id" value="${regionDTO.id}"/><f:message key="remove"/></s:link>
                                                </td>
                                                <td>
                                                    <s:link beanclass="cz.muni.fi.pa165.creatures.web.RegionsActionBean" event="edit">
                                                    <s:param name="regionDTO.id" value="${regionDTO.id}"/><f:message key="edit"/></s:link>
                                                </td>
                                            </ss:secure>
                                            <td>
                                                <s:link beanclass="cz.muni.fi.pa165.creatures.web.RegionsActionBean" event="detail">
                                                <s:param name="regionDTO.id" value="${regionDTO.id}"/><f:message key="detail"/></s:link>
                                            </td>
                                            <ss:secure roles="admin">
                                                <td><s:checkbox name="selected" value="${regionDTO.id}"/></td>
                                            </ss:secure>
                                        </tr>
                                    </c:forEach>
                                </c:when>
                                <c:otherwise>
                                    <tr>
                                        <td colspan="6"><f:message key="region.no_records_found"/></td>
                                    </tr>
                                </c:otherwise>
                            </c:choose>
                            <tr>
                                <td><f:message key="total_count"/></td>
                                <td colspan="7">${regionAB.count}</td>
                            </tr>
                        </tbody>
                    </table>
                    <ss:secure roles="admin">
                        <c:if test="${regionAB.count > 0}">
                              <s:submit name="deleteSelected"><f:message key="remove_selected"/></s:submit>
                        </c:if>
                    </ss:secure>
                </s:form>
            </div>
        </div>
    </s:layout-component>
</s:layout-render>